# MySQL MCP Server Dockerfile
# 基于 Python 3.11 的轻量级镜像

FROM python:3.11-slim

# 设置工作目录
WORKDIR /app

# 设置环境变量
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    gcc \
    default-libmysqlclient-dev \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

# 复制需求文件
COPY requirements.txt .

# 安装 Python 依赖
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# 复制项目文件
COPY src/ ./src/
COPY setup.py .
COPY README.md .
COPY LICENSE .

# 安装项目
RUN pip install -e .

# 创建非root用户
RUN groupadd -r mcpuser && useradd -r -g mcpuser mcpuser
RUN chown -R mcpuser:mcpuser /app
USER mcpuser

# 暴露端口（如果需要HTTP接口）
# EXPOSE 8080

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "import src.mysql_mcp_server; print('OK')" || exit 1

# 设置默认命令
CMD ["python", "-m", "src.mysql_mcp_server.main"]

# 构建信息标签
LABEL maintainer="MySQL MCP Server Team"
LABEL version="1.0.0"
LABEL description="MySQL MCP Server - A Model Context Protocol server for MySQL databases"
LABEL org.opencontainers.image.source="https://github.com/your-org/mysql-mcp-server"
LABEL org.opencontainers.image.documentation="https://github.com/your-org/mysql-mcp-server/blob/main/README.md"
LABEL org.opencontainers.image.licenses="MIT"